package com.mindskip.xzs.controller.admin;

import com.github.pagehelper.PageInfo;
import com.mindskip.xzs.domain.dto.admin.message.MessagePageDTO;
import com.mindskip.xzs.domain.dto.admin.message.MessageSendDTO;
import com.mindskip.xzs.domain.vo.admin.message.MessageVO;
import com.mindskip.xzs.service.MessageService;
import com.mindskip.xzs.utility.RestResponse;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController("AdminMessageController")
@RequestMapping(value = "/api/admin/message")
public class MessageController {

    private final MessageService messageService;

    public MessageController(MessageService messageService) {
        this.messageService = messageService;
    }


    @PostMapping("/page")
    public RestResponse<PageInfo<MessageVO>> page(@RequestBody MessagePageDTO messagePageDTO) {

        PageInfo<MessageVO> messageByPage = messageService.getMessageByPage(messagePageDTO);
        return RestResponse.ok(messageByPage);
    }

    @PostMapping("/send")
    public RestResponse<Object> send(@RequestBody @Valid MessageSendDTO messageSendDTO) {

        messageService.sendMessage(messageSendDTO);
        return RestResponse.ok();
    }
}
